import sys
from PyQt5.QtWidgets import QApplication, QWidget, QCheckBox, QVBoxLayout


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建复选框（开关）
        self.checkBox_a = QCheckBox("only A")
        self.checkBox_a.stateChanged.connect(self.print_state_a)
        
        # 创建复选框（开关）
        self.checkBox_b = QCheckBox("only B")
        self.checkBox_b.stateChanged.connect(self.print_state_b)

        layout = QVBoxLayout()
        layout.addWidget(self.checkBox_a)
        layout.addWidget(self.checkBox_b)
        self.setLayout(layout)

        self.setWindowTitle("switch button true/false")
        self.setGeometry(300, 300, 200, 150)
        self.show()

    def print_state_a(self, state):
        if state == 2:
            self.checkBox_b.setChecked(False)
            print(True)
        else:
            self.checkBox_b.setChecked(True)
            print(False)
            
    def print_state_b(self, state):
        if state == 2:
            print(True)
            self.checkBox_a.setChecked(False)
        else:
            print(False)
            self.checkBox_a.setChecked(True)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
